import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:work/pages/main/app_bottom_bar.dart';
import 'package:work/util/help.dart';

class MainController extends GetxController {
  static MainController get to => Get.find<MainController>();

  final pageController = PageController(initialPage: 0);

  final current = 0.obs;

  final visible = false.obs;

  static const items = [
    AppBottomNavigationBarItem(
      text: 'Game',
      icon: 'assets/tabbar/icon_1.png',
      activeIcon: 'assets/tabbar/icon_1_on.png',
    ),
    AppBottomNavigationBarItem(
      text: 'Earn',
      icon: 'assets/tabbar/icon_2.png',
      activeIcon: 'assets/tabbar/icon_2_on.png',
    ),
    AppBottomNavigationBarItem(
      text: 'Cashout',
      icon: 'assets/tabbar/icon_4.png',
      activeIcon: 'assets/tabbar/icon_4_on.png',
    ),
  ];

  @override
  void onReady() async {
    super.onReady();
    // _onPrecache();
    visible.value = true;
  }

  /// 预加载图片，防止切换闪烁
  // void _onPrecache() {
  //   for (var item in items) {
  //     Help.precacheAssetImage(item.icon);
  //     Help.precacheAssetImage(item.activeIcon);
  //   }
  // }

  /// 底部TAB修改
  void onPageChanged(int index) {
    current.value = index;
  }
}
